#include "launchdialog.h"
#include "ui_launchdialog.h"
#include "authoritymanager.h"
#include <QMessageBox>
LaunchDialog::LaunchDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LaunchDialog)
{
    setWindowFlags(Qt::WindowCloseButtonHint  | Qt::Dialog);

    ui->setupUi(this);
	QString v = QCoreApplication::applicationVersion();
	setWindowTitle("BGA Vision System " + v);
	//setWindowTitle("网格阵列芯片外观检测系统 V1.0");
    connect(ui->loginBtn, &QPushButton::clicked, [=](){
//        AuthorityManager *m = AuthorityManager::getInstance();
//        bool b = m->checkPwd(ui->pwdLineEdit->text(), static_cast<AuthorityManager::AUTH_LEVEL>(ui->comboBox->currentIndex()));
//        if (b)
//        {
//            QDialog::accept();
//        }
//        else
        {
            QMessageBox box(QMessageBox::Warning, tr("Error"), tr("Please input correct password！"));
            box.setStandardButtons (QMessageBox::Ok);
            box.setButtonText (QMessageBox::Ok, tr(" OK "));
            box.exec();

            ui->pwdLineEdit->clear();
            ui->pwdLineEdit->setFocus();
        }

    });
    connect(ui->quitBtn, &QPushButton::clicked, [=](){
        QDialog::reject();
    });

    connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(ComboBoxIndexChanged(int)));
    resize(300, 200);
}

LaunchDialog::~LaunchDialog()
{
    delete ui;
}

void LaunchDialog::ComboBoxIndexChanged(int index)
{
    ui->pwdLineEdit->setEnabled(index!=0);
}
